using Microsoft.AspNetCore.Mvc;     // 因为ControllerBase等需要引入
using MyWebApi.Api.Entity;      // 因为Users表需要引入
using System.Collections.Generic;   // 因为泛型需要引入
using System.Linq;     // 因为Where 引入之后我们可以使用一种类似SQL的语法来查询任何形式的数据
using System;
using MyWebApi.Api.Repository;
using MyWebApi.Api.ParamModel;
using MyWebApi.Api.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;


// 
// 商品控制器
// 

namespace MyWebApi.Api.Controllers
{
    // 特性
    // [Authorize]  // [Authorize]下的所有Api接口如：查询、删除、创建用户不能匿名访问，需要Token令牌才可访问
    [ApiController]
    [Route("[controller]")]

    public class CommodityController : ControllerBase
    {

        // 实例化数据库
        // private MyWebApi.Api.Db.MyWebApiDb db = new Db.MyWebApiDb();

        // 定义为IRepository<T>的泛型接口未知数 T 为 users
        private IRepository<users> _usersRespository;   // 现在_usersRespository里包含IRepository<T>泛型接口里面的属性(可以使用这些属性来进行对Users表的操作)
        private IRepository<commodity> _commodity;   // 商品表
        private IRepository<commodity_property> _commodity_property;
        private IRepository<commodity_property_vel> _commodity_property_vel;
        private IRepository<commodity_picture> _commodity_picture;
        private IRepository<appraise> _appraise;

        // 文件上传需要
        private readonly IWebHostEnvironment _hostingEnvironment;


        private TokenParameter _tokenParameter;
        private readonly IConfiguration _configuration;

        // 一个构造函数：初始化UsersController控制器，使该控制器一开始就有以下的属性
        public CommodityController(IConfiguration configuration,
        IWebHostEnvironment hostingEnvironment,
         IRepository<users> usersRespository,
         IRepository<commodity> commodity,
         IRepository<commodity_property> commodity_property,
         IRepository<commodity_property_vel> commodity_property_vel,
         IRepository<commodity_picture> commodity_picture,
         IRepository<appraise> appraise

         )
        {
            // 文件上传需要
            _hostingEnvironment = hostingEnvironment;

            _configuration = configuration;
            _tokenParameter = _configuration.GetSection("tokenParameter").Get<TokenParameter>();

            _usersRespository = usersRespository;
            _commodity = commodity;
            _commodity_property = commodity_property;
            _commodity_property_vel = commodity_property_vel;
            _commodity_picture = commodity_picture;
            _appraise = appraise;
        }


        // 添加商品
        [HttpPost]
        public dynamic addCommodity()
        {
            // 获取前端FormData中的文件
            var files = HttpContext.Request.Form.Files;

            string webRootPath = _hostingEnvironment.WebRootPath;// 获取目录下的...Api/wwwroot路径 
            var showfilePath = FileSaveHelper.Filesave(files, webRootPath);  // 封装的文件处理方法

            // 获取前端FormData中的数据
            // 商品名称
            var commodityName = HttpContext.Request.Form["commodityName"];
            // 介绍
            var introduce = HttpContext.Request.Form["Introduce"];
            // 供应商Id
            var supplierId = HttpContext.Request.Form["supplierId"];
            // 分类Id
            var classifyId = HttpContext.Request.Form["classifyId"];


            if (commodityName != "" && introduce != "")
            {
                // 添加商品
                var commodity = new commodity
                {
                    commodityName = commodityName,
                    Introduce = introduce,
                    surfacePlot = showfilePath,
                    supplierId = Int32.Parse(supplierId),
                    classifyId = Int32.Parse(classifyId)
                };
                _commodity.Insert(commodity);

                var res = new
                {
                    Code = 1000,
                    Data = commodity,
                    Msg = "添加商品成功"
                };
                return JsonHelper.Serialize(res);
            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = "商品名称和商品介绍不能为空",
                    Msg = "商品名称和商品介绍不能为空"
                };
                return JsonHelper.Serialize(res);
            }

        }


        // 根据id更新商品状态（上架或下架）
        [HttpPost, Route("upcommoditystatus/{id}")]
        public dynamic upCommodity(int id, CommodityModel model)
        {
            // 商品状态
            var commodityStatus = model.status;

            var getCommodity = _commodity.GetById(id);
            getCommodity.Status = commodityStatus;
            _commodity.Update(getCommodity);

            var res = new
            {
                Code = 1000,
                Data = getCommodity,
                Msg = string.Format("更新id为{0}的商品状态成功", id)
            };
            return JsonHelper.Serialize(res);
        }


        // 根据id删除商品（伪删除）
        [HttpPost, Route("delcommodity/{id}")]
        public dynamic delCommodity(int id)
        {
            var delCommodityId = _commodity.GetById(id);
            delCommodityId.IsDeleted = true;
            _commodity.Update(delCommodityId);

            var res = new
            {
                Code = 1000,
                Data = delCommodityId,
                Msg = string.Format("删除id为{0}的商品状态成功", id)
            };
            return JsonHelper.Serialize(res);
        }


        // 添加商品规格（属性(颜色、尺寸)）
        [HttpPost, Route("commodityproperty")]
        public dynamic commodityProperty(PropertyModel model)
        {
            // 商品Id
            var commodityId = model.commodityId;

            // 属性
            var property = model.Property;

            var allProperty = _commodity_property.Table.Where(x => x.commodityId == commodityId && x.property == property).ToList();

            if (allProperty.Count() > 0)
            {
                var res = new
                {
                    Code = 1001,
                    Data = "该商品存在相同的属性",
                    Msg = "该商品存在相同的属性"
                };

                return JsonHelper.Serialize(res);
            }
            else
            {
                var commodityProperty = new commodity_property
                {
                    commodityId = commodityId,
                    property = property
                };
                _commodity_property.Insert(commodityProperty);

                var res = new
                {
                    Code = 1000,
                    Data = commodityProperty,
                    Msg = string.Format("添加商品Id为{0}的属性成功", commodityId)
                };

                return JsonHelper.Serialize(res);
            }





        }


        // 根据商品id查询商品规格（属性(颜色、尺寸)）
        [HttpGet, Route("selcommodityproperty/{commodityId}")]
        public dynamic selCommodityProperty(int commodityId)
        {
            var getIdCommodityproperty = _commodity_property.Table.Where(x => x.commodityId == commodityId && x.IsDeleted == false).ToList();
            var res = new
            {
                Code = 1000,
                Data = getIdCommodityproperty,
                Msg = string.Format("查询商品id为{0}的属性成功", commodityId)
            };
            return JsonHelper.Serialize(res);
        }


        // 添加商品规格值（属性值（红色、蓝色、xxl、xl、l））
        [HttpPost, Route("property_vel")]
        public dynamic propertyVel(PropertyModel model)
        {
            // 商品属性id
            var commodityNormsId = model.CommodityNormsId;
            // 属性值(红色、白色...)
            var propertyVel = model.PropertyVel;
            // 库存
            var repertory = model.Repertory;
            // 价格
            var money = model.Money;

            var filterProperty = _commodity_property_vel.Table.Where(x => x.commodityNormsId == commodityNormsId && x.PropertyVel == propertyVel).ToList();

            if (filterProperty.Count() > 0)
            {
                var res = new
                {
                    Code = 1001,
                    Data = "该商品属性已存在该属性值，添加失败",
                    Msg = "该商品属性已存在该属性值，添加失败"
                };
                return JsonHelper.Serialize(res);
            }
            else
            {
                var commodity_property_vel = new commodity_property_vel
                {
                    commodityNormsId = commodityNormsId,
                    PropertyVel = propertyVel,
                    repertory = repertory,
                    money = money
                };
                _commodity_property_vel.Insert(commodity_property_vel);

                var res = new
                {
                    Code = 1000,
                    Data = commodity_property_vel,
                    Msg = string.Format("添加商品属性id为{0}的属性值成功", commodityNormsId)
                };
                return JsonHelper.Serialize(res);
            }



        }


        // 根据商品属性id查询商品属性值（属性值（红色、蓝色、xxl、xl、l））
        [HttpGet, Route("selproperty_vel/{propertyvelId}")]
        public dynamic selpropertyVel(int propertyvelId)
        {
            var selproperty_vel = _commodity_property_vel.Table.Where(x => x.commodityNormsId == propertyvelId && x.IsDeleted == false).ToList();
            var res = new
            {
                Code = 1000,
                Data = selproperty_vel,
                Msg = string.Format("查询商品属性id为{0}的属性值成功", propertyvelId)
            };
            return JsonHelper.Serialize(res);
        }


        // 查询所有商品(商品创建时间倒序)(用户界面)(商品得要有商品属性和属性值才能查询出来)
        [HttpGet]
        public dynamic getCommodity()
        {

            // 所有商品连接规格表
            var commodityJoinProperty = from allCommodity in _commodity.Table
                                        join commodity_property in _commodity_property.Table on allCommodity.Id equals commodity_property.commodityId
                                        join commodity_property_vel in _commodity_property_vel.Table on commodity_property.Id equals commodity_property_vel.commodityNormsId
                                        where allCommodity.IsDeleted == false && allCommodity.Status == true
                                        select new
                                        {
                                            CommodityId = allCommodity.Id,
                                            CommodityName = allCommodity.commodityName,
                                            Introduce = allCommodity.Introduce,
                                            SurfacePlot = allCommodity.surfacePlot,
                                            SupplierId = allCommodity.supplierId,
                                            ClassifyId = allCommodity.classifyId,
                                            CreatedTime = allCommodity.CreatedTime,

                                            Property = commodity_property.property == null ? "未存在属性" : commodity_property.property,

                                            PropertyVel = commodity_property_vel.PropertyVel == null ? "未存在属性值" : commodity_property_vel.PropertyVel,
                                            Repertory = commodity_property_vel.repertory == 0 ? 0 : commodity_property_vel.repertory,
                                            Money = commodity_property_vel.money == 0 ? 0 : commodity_property_vel.money,

                                        };

            var OrderByCommodityJoinProperty = commodityJoinProperty.OrderByDescending(x => x.CreatedTime);

            var res = new
            {
                Code = 1000,
                Data = OrderByCommodityJoinProperty,
                Msg = "查询所有商品成功"
            };
            return JsonHelper.Serialize(res);
        }


        // 查询所有商品(管理员界面)(不进行连接商品属性和属性值,因为连接查询属性表为空的话查不出来)(分页)
        [HttpGet, Route("adminselcommodity")]
        public dynamic adminSelCommodity([FromQuery] Pager pager)
        {
            var pageIndex = pager.pageIndex;
            var pageSize = pager.pageSize;

            // 所有商品
            var allCommodity = _commodity.Table.Where(x => x.IsDeleted == false).ToList().OrderByDescending(x => x.CreatedTime);

            var PGR = allCommodity.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

            var res = new
            {
                Code = 1000,
                Data = new { data = PGR, pager = new { pageIndex, pageSize, rowsTotal = allCommodity.Count() } },
                Msg = "查询所有商品成功(根据创建时间倒序)"
            };
            return JsonHelper.Serialize(res);
        }

        // 根据Id查询商品
        [HttpGet, Route("get_id_commodity/{commodityId}")]
        public dynamic getIdCommodity(int commodityId)
        {
            var isId = _commodity.GetById(commodityId);
            if (isId != null)
            {
               // 所有商品连接规格表
            var commodityJoinProperty = from allCommodity in _commodity.Table
                                        join commodity_property in _commodity_property.Table on allCommodity.Id equals commodity_property.commodityId
                                        join commodity_property_vel in _commodity_property_vel.Table on commodity_property.Id equals commodity_property_vel.commodityNormsId
                                        where allCommodity.IsDeleted == false && allCommodity.Status == true && allCommodity.Id == commodityId
                                        select new
                                        {
                                            CommodityId = allCommodity.Id,
                                            CommodityName = allCommodity.commodityName,
                                            CommodityIntroduce = allCommodity.Introduce,

                                            Property = commodity_property.property == null ? "未存在属性" : commodity_property.property,

                                            PropertyVel = commodity_property_vel.PropertyVel == null ? "未存在属性值" : commodity_property_vel.PropertyVel,
                                            Repertory = commodity_property_vel.repertory == 0 ? 0 : commodity_property_vel.repertory,
                                            Money = commodity_property_vel.money,

                                        };


            var res = new
            {
                Code = 1000,
                Data = commodityJoinProperty,
                Msg = string.Format("查询Id为{0}的商品成功", commodityId)
            };
            return JsonHelper.Serialize(res);
            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = "商品不存在",
                    Msg = string.Format("Id为{0}的商品不存在", commodityId)
                };
                return JsonHelper.Serialize(res);
            }



        }


        // 根据商品Id修改商品
        [HttpPost, Route("up_commodity/{commodityId}")]
        public dynamic updateCommodity(int commodityId, CommodityModel model)
        {
            var isId = _commodity.GetById(commodityId);
            var commodityName = model.commodityName;
            var Introduce = model.Introduce;

            if (isId != null)
            {
                if (commodityName != "" && Introduce != "")
                {
                    isId.commodityName = commodityName;
                    isId.Introduce = Introduce;

                    _commodity.Update(isId);
                    var res = new
                    {
                        Code = 1000,
                        Data = isId,
                        Msg = "更新商品名称和介绍成功"
                    };
                    return JsonHelper.Serialize(res);

                }
                else
                {
                    var res = new
                    {
                        Code = 1001,
                        Data = "商品标题和商品介绍不能为空哦",
                        Msg = "商品标题和商品介绍不能为空哦"
                    };
                    return JsonHelper.Serialize(res);
                }

            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = "商品不存在",
                    Msg = string.Format("Id为{0}的商品不存在", commodityId)
                };
                return JsonHelper.Serialize(res);
            }
        }


        // 根据属性Id修改商品属性
        [HttpPost, Route("up_property/{propertyId}")]
        public dynamic upProperty(int propertyId, PropertyModel model)
        {
            var isId = _commodity_property.GetById(propertyId);
            var Property = model.Property;

            if (isId != null && isId.IsDeleted != true)
            {
                if (Property != "")
                {
                    isId.property = Property;

                    _commodity_property.Update(isId);
                    var res = new
                    {
                        Code = 1000,
                        Data = isId,
                        Msg = string.Format("Id为{0}的商品属性成功", propertyId)
                    };
                    return JsonHelper.Serialize(res);

                }
                else
                {
                    var res = new
                    {
                        Code = 1001,
                        Data = "商品属性不能为空哦",
                        Msg = "商品属性不能为空哦"
                    };
                    return JsonHelper.Serialize(res);
                }

            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = "商品不存在",
                    Msg = string.Format("Id为{0}的商品属性不存在", propertyId)
                };
                return JsonHelper.Serialize(res);
            }
        }


        // 根据属性Id删除商品属性
        [HttpPost, Route("del_property/{propertyId}")]
        public dynamic delProperty(int propertyId)
        {
            var delProperty = _commodity_property.GetById(propertyId);
            delProperty.IsDeleted = true;
            _commodity_property.Update(delProperty);

            var res = new
            {
                Code = 1000,
                Data = delProperty,
                Msg = string.Format("删除Id为{0}的商品属性成功", propertyId)
            };
            return JsonHelper.Serialize(res);
        }


        // 根据属性值Id修改属性值
        [HttpPost, Route("up_property_vel/{propertyVelId}")]
        public dynamic upPropertyVel(int propertyVelId, PropertyModel model)
        {

            var isId = _commodity_property_vel.GetById(propertyVelId);

            var PropertyVel = model.PropertyVel;
            var Repertory = model.Repertory;
            var Money = model.Money;

            if (isId != null && isId.IsDeleted != true)
            {
                if (PropertyVel != "")
                {
                    isId.PropertyVel = PropertyVel;
                    isId.repertory = Repertory;
                    isId.money = Money;

                    _commodity_property_vel.Update(isId);
                    var res = new
                    {
                        Code = 1000,
                        Data = isId,
                        Msg = string.Format("Id为{0}的商品属性值成功", propertyVelId)
                    };
                    return JsonHelper.Serialize(res);

                }
                else
                {
                    var res = new
                    {
                        Code = 1001,
                        Data = "商品属性值不能为空哦",
                        Msg = "商品属性值不能为空哦"
                    };
                    return JsonHelper.Serialize(res);
                }

            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = "商品不存在",
                    Msg = string.Format("Id为{0}的商品属性不存在", propertyVelId)
                };
                return JsonHelper.Serialize(res);
            }

        }

        // 根据属性值Id删除属性值
        [HttpPost, Route("del_property_vel/{propertyVelId}")]
        public dynamic delPropertyVel(int propertyVelId)
        {
            var delPropertyVel = _commodity_property_vel.GetById(propertyVelId);
            delPropertyVel.IsDeleted = true;
            _commodity_property_vel.Update(delPropertyVel);

            var res = new
            {
                Code = 1000,
                Data = delPropertyVel,
                Msg = string.Format("删除Id为{0}的商品属性值成功", delPropertyVel)
            };
            return JsonHelper.Serialize(res);
        }


        // 根据商品Id和属性Id减属性值的库存
        [HttpPost, Route("minus_repertory")]
        public dynamic minusRepertory(PropertyModel model)
        {
            // 商品Id
            var commodityId = model.commodityId;
            // 属性Id
            var PropertyId = model.CommodityNormsId;

            // 要减库存的商品属性值Id
            var PropertyVelId = model.PropertyVelId;
            // 要减去的库存数量
            var minusSum = model.minusSum;

            var isId = _commodity.GetById(commodityId);
            // 判断商品是否存在
            if (isId != null)
            {
                // 通过商品Id查询到该商品的属性,然后通过商品属性Id查询到该商品属性值,然后减去该商品属性值的库存数量
                // 查询商品属性
                var commodityNorms = _commodity_property.Table.Where(x => x.commodityId == commodityId && x.Id == PropertyId && x.IsDeleted == false).ToList().FirstOrDefault();


                // 查询商品属性值
                var commodityPropertyVel = _commodity_property_vel.Table.Where(x => x.commodityNormsId == commodityNorms.Id && x.Id == PropertyVelId && x.IsDeleted == false).ToList().FirstOrDefault();

                if (commodityPropertyVel != null)
                {
                    // 查询当前库存总数
                    var repertoryCount = commodityPropertyVel.repertory;

                    commodityPropertyVel.repertory = (commodityPropertyVel.repertory - minusSum);

                    _commodity_property_vel.Update(commodityPropertyVel);


                    var res = new
                    {
                        Code = 1000,
                        Data = commodityPropertyVel,
                        Msg = string.Format("减去商品Id为{0}的库存成功", commodityId)
                    };
                    return JsonHelper.Serialize(res);
                }
                else
                {
                    var res = new
                    {
                        Code = 1001,
                        Data = "该属性的属性值不存在",
                        Msg = "该属性的属性值不存在"
                    };
                    return JsonHelper.Serialize(res);
                }


            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = "商品不存在",
                    Msg = "商品不存在"
                };
                return JsonHelper.Serialize(res);
            }



        }


        // 用户界面查询所有商品
        [HttpGet, Route("sel_commodity")]
        public dynamic selCommodity()
        {
            var allCommodity = _commodity.Table.Where(x => x.IsDeleted == false).OrderByDescending(x => x.CreatedTime).ToList();


            var res = new
            {
                Code = 1000,
                Data = allCommodity,
                Msg = "查询所有商品成功"
            };
            return JsonHelper.Serialize(res);
        }



        // # ======================================================================================
        // #       商品图片
        // # ======================================================================================


        // 添加商品图片
        [HttpPost, Route("add_commodity_picture")]
        public dynamic addCommodityPicture()
        {

            var files = HttpContext.Request.Form.Files;

            string webRootPath = _hostingEnvironment.WebRootPath;
            var picturePath = FileSaveHelper.Filesave(files, webRootPath);

            var commodityId = HttpContext.Request.Form["commodityId"];


            var addCommodityPicture = new commodity_picture
            {
                picture = picturePath,
                commodityId = Int32.Parse(commodityId)
            };
            _commodity_picture.Insert(addCommodityPicture);


            var res = new
            {
                Code = 1000,
                Data = addCommodityPicture,
                Msg = string.Format("添加id为{0}的商品图片成功", commodityId)
            };
            return JsonHelper.Serialize(res);

        }

        // 根据Id删除商品图片
        [HttpPost, Route("del_commodity_picture/{id}")]
        public dynamic delCommodityPicture(int id)
        {
            var delCommodityPictureId = _commodity_picture.GetById(id);
            if (delCommodityPictureId != null)
            {
                delCommodityPictureId.IsDeleted = true;
                _commodity_picture.Update(delCommodityPictureId);

                var res = new
                {
                    Code = 1000,
                    Data = delCommodityPictureId,
                    Msg = string.Format("删除id为{0}的商品图片成功", id)
                };
                return JsonHelper.Serialize(res);
            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = string.Format("删除id为{0}的商品图片失败", id),
                    Msg = string.Format("删除id为{0}的商品图片失败", id)
                };
                return JsonHelper.Serialize(res);
            }
        }

        // 根据商品Id查询出该商品的所有图片
        [HttpGet, Route("sel_commodity_picture/{commodityId}")]
        public dynamic selCommodityPicture(int commodityId)
        {
            var isId = _commodity_picture.Table.Where(x => x.IsDeleted == false && x.commodityId == commodityId).ToList();

            if (isId.Count() > 0)
            {
                var selCommodityPicture = _commodity_picture.Table.Where(x => x.IsDeleted == false && x.commodityId == commodityId).ToList();

                var res = new
                {
                    Code = 1000,
                    Data = selCommodityPicture,
                    Msg = string.Format("查询商品id为{0}的商品图片成功", commodityId)
                };
                return JsonHelper.Serialize(res);
            }
            else
            {

                var res = new
                {
                    Code = 1001,
                    Data = string.Format("查询商品id为{0}的商品图片失败", commodityId),
                    Msg = string.Format("查询商品id为{0}的商品图片失败", commodityId)
                };
                return JsonHelper.Serialize(res);
            }

        }



        // # ======================================================================================
        // #       评价等级
        // # ======================================================================================

        // 添加评价等级
        [HttpPost, Route("add_appraise")]
        public dynamic addAppraise(AppraiseModel model)
        {
            var commodityId = model.CommodityId;
            var appraiseEstate = model.AppraiseEstate;
            var appraiseUserId = model.AppraiseUserId;

            if (commodityId != 0)
            {
                var addAppraise = new appraise
                {
                    commodityId = commodityId,
                    appraiseEstate = appraiseEstate,
                    appraiseUserId = appraiseUserId
                };
                _appraise.Insert(addAppraise);

                var res = new
                {
                    Code = 1000,
                    Data = addAppraise,
                    Msg = "感谢您对该商品的评价"
                };
                return JsonHelper.Serialize(res);

            }
            else
            {
                var res = new
                {
                    Code = 1001,
                    Data = "添加评价失败，未收到商品id",
                    Msg = "添加评价失败，未收到商品id"
                };
                return JsonHelper.Serialize(res);
            }
        }

        // 根据商品Id查询某个商品的好评率和差评率
        [HttpGet, Route("sel_appraise/{commodityId}")]
        public dynamic selAppraise(int commodityId)
        {
            var isCcommodityId = _appraise.Table.Where(x => x.IsDeleted == false && x.commodityId == commodityId);
            if (isCcommodityId.Count() > 0)
            {

                // 好评差评总数
                var appraiseSum = isCcommodityId.Count();

                // 好评总数
                float goodSum = _appraise.Table.Where(x => x.IsDeleted == false && x.appraiseEstate == "好评").ToList().Count();
                // 差评总数
                var negativeSum = _appraise.Table.Where(x => x.IsDeleted == false && x.appraiseEstate == "差评").ToList().Count();

                // 计算好评公式
                var goodRate = ((double)goodSum / appraiseSum) * 100;
                // 计算好评公式
                var negativeRate = ((double)negativeSum / appraiseSum) * 100;

                var res = new
                {
                    Code = 1000,
                    Data = new { GoodRate = Math.Round(goodRate, 2) + "%", NegativeRate = Math.Round(negativeRate, 2) + "%" },
                    Msg = string.Format("该商品{0}评价查询成功,好评率为{1}%,差评率为{2}%", commodityId, goodRate, negativeRate)
                };
                return JsonHelper.Serialize(res);
            }
            else
            {

                var res = new
                {
                    Code = 1001,
                    Data = string.Format("该商品{0}暂未有评价", commodityId),
                    Msg = string.Format("该商品{0}暂未有评价", commodityId)
                };
                return JsonHelper.Serialize(res);
            }
        }





    }

}